home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM Today - The Disc! 5
/
CD-ROM Today - The Disc (Issue 5)(November 1994).ISO
/
mac
/
Mac shareware
/
Education
/
RLaB
/
help
/
IF
< prev
next >
Wrap
Text File
|
1994-09-21
|
829b
|
48 lines
IF:
The if statement is very similar to the C if statement.
if ( expression )
{
statement(s)
else
statement(s)
}
The "else" is optional, and the braces are always required.
The differences between the C-language if-statement and RLaB's
are due to the special demands of an interactive language.
Examples:
if ( init )
{
mass = 10.0;
inertia = 3*mass/length^3;
init = 0;
}
if(class(data) == "string")
{
fprintf(file, data);
else
write(file, data);
}
if( class(v) != "matrix" ) { error(); }
At present there is no explicit elseif statement. However the
else if behavior can be implemented as it is in C (although
RLaB's syntax is somewhat clumsy). For example:
if( test1 )
{
x = a;
else if( test2 ) {
x = b;
else if( test3 ) {
x = c;
else
error();
}}}